# Reference on this file: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
# You need to add BrowserStack access keys in order for the tests to work. Get a BrowserStack automate account, then go
# to the repository settings, the Secrets page and add secrets: BROWSERSTACK_USERNAME, BROWSERSTACK_ACCESS_KEY.
name: Lint and test
on:
  push:
    branches:
      - master
  pull_request:
    paths-ignore:
      - '**.md'
      - playground/**
jobs:
  test:
    name: Lint and test
    runs-on: ubuntu-latest
    timeout-minutes: 15
    concurrency: browserstack
    steps:
      # TypeScript types are checked during building and testing so there is no need for a separate step for the check
      - name: Checkout
        uses: actions/checkout@v3
      - name: Cache
        uses: actions/cache@v3
        with:
          path: node_modules
          key: nodemodules-${{ hashFiles('yarn.lock') }}
          restore-keys: nodemodules-
      - name: Install Node packages
        run: yarn install
      - name: Lint
        run: yarn lint
      - name: Build
        run: yarn build
      - name: Check the distributive TypeScript declarations
        run: yarn check:dts
        # Helps to prevent https://github.com/fingerprintjs/fingerprintjs/issues/602
      - name: Check the ability to work with server side rendering
        run: yarn check:ssr
      - name: Test on BrowserStack
        env:
          BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
          BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
        run: yarn test:browserstack --log-level ${{ runner.debug == '1' && 'debug' || 'info' }}
